package com.sinothk.gpserver.modules.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sinothk.gpserver.modules.biz.service.IUserScoreService;
import com.sinothk.gpserver.modules.system.entity.UserEntity;
import com.sinothk.gpserver.modules.system.mapper.LoginMapper;
import com.sinothk.gpserver.modules.system.mapper.UserMapper;
import com.sinothk.gpserver.modules.system.service.IUserService;
import com.sinothk.server.support.entity.PageData;
import com.sinothk.server.support.entity.PageVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户相关 服务实现类
 * </p>
 *
 * @author Liang Y.t.
 * @since 2021-08-27
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements IUserService {

    @Resource
    private LoginMapper loginMapper;
    @Resource
    private UserMapper userMapper;

    private final IUserScoreService userScoreService;

    public UserServiceImpl(IUserScoreService userScoreService) {
        this.userScoreService = userScoreService;
    }

    /**
     * 查询分页数据
     *
     * @param pageVo 分页参数
     * @return PageData
     */
    @Override
    public PageData<UserEntity> page(PageVo<UserEntity> pageVo) {
        Page<UserEntity> page = new Page<>(pageVo.getPageNum(), pageVo.getPageSize());
        Page<UserEntity> userIPage = userMapper.selectPage(page, null);

        // 组装
        PageData<UserEntity> rspPageData = new PageData<>();
        rspPageData.setPageNum(userIPage.getCurrent());
        rspPageData.setPageSize(userIPage.getSize());
        rspPageData.setCurrent(userIPage.getCurrent());
        rspPageData.setTotal(userIPage.getTotal());
        rspPageData.setData(userIPage.getRecords());

        return rspPageData;
    }

    @Override
    public UserEntity getByAccount(String account) {
        return userMapper.selectByAccount(account);
    }
}
